package org.ch00.test01;

import java.util.Arrays;

/**
 * @author ZJL
 * @date 2025-02-28
 */
public class Phone {
    /**
     * 品牌
     */
    private String brand;
    /**
     * 价格
     */
    private double price;
    /**
     * 名称
     */
    private String name;
    /**
     * 联系人 (约定最多只能存储 10 个联系人)
     */
    private String[] contactList;

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String[] getContactList() {
        return contactList;
    }

    public void setContactList(String[] contactList) {
        if (contactList.length < 10) {
            this.contactList = contactList;
        } else {
            this.contactList = Arrays.copyOfRange(contactList, 0, 10);
            System.out.println("最多只能存储10个联系人");
        }
    }

    /**
     * 上网
     */
    public void netPlay() {
        System.out.println(this.name + "正在上网...");
    }

    /**
     * 给某个联系人发送信息
     * 如果联系人
     *
     * @param contactName
     * @param note
     */
    public void callNote(String contactName, String note) {
        boolean flag = false;
        for (String contact : contactList) {
            if (contact != null && contact.equals(contactName)) {
                System.out.println("给" + contact + "发送" + note);
                flag = true;
                break;
            }
        }
        if (!flag) {
            System.out.println("给匿名用户发送" + note);
        }
    }

    @Override
    public String toString() {
        return "Phone{" +
                "brand='" + brand + '\'' +
                ", price=" + price +
                ", name='" + name + '\'' +
                ", contactList=" + Arrays.toString(contactList) +
                '}';
    }
}
